/**
 *
 * @author DnD Binary Source
 */

package AbstractClasses;

import binarysource.StartScreen;
import Interfaces.Iterator;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;

public abstract class Lista implements Iterator, Serializable{
    private int actualIndex = -1;
    protected List<Object> elements;

    public abstract void add(Object object);
    public abstract void remove(int position);
    public abstract void updateItem();

    public Object returnObject(int position){
        return this.elements.get(position);
    }

    public final int listSize(){
        if(elements==null){
            elements = new ArrayList<Object>();
        }return elements.size();
    }

    public final int returnIndex(){
        return actualIndex;
    }

    public final void startIterator(){
        actualIndex = -1;
    }

    public final Object first(){
        if(hasElement()){ 
            return elements.get(0);
        }
        else
            return null;
    }

    public final Object last(){
        if(hasElement()){
            return elements.get(elements.size()-1);
        }
        else
            return null;
    }

    public final boolean hasElement(){
        return (actualIndex+1) < elements.size();
    }

    public final Object next(){
        if(hasElement()){
            actualIndex++;
            return elements.get(actualIndex);
        }
        else{
            return null;
        }
    }
}
